package com.yuncheng.oaApi.FlowController;


import com.yuncheng.entity.YcSysUser;
import com.yuncheng.oaApi.vo.NkRsCcSpVo;
import com.yuncheng.oaApi.vo.OaFlowVo;
import com.yuncheng.oaApi.vo.OaReturnVo;
import com.yuncheng.oaApi.vo.Result;
import com.yuncheng.spcyApi.service.ISpcyLogService;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.oaApi.FlowService.NewNkRsCcSpFlowService;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.oaApi.busService.OaFlowNodeDbrService;
import com.yuncheng.oaApi.busService.MyLcFlowService;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.constant.OaFlowConstant;
import com.yuncheng.oaApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.oaApi.mapper.NkRsCcSpFlowMapper;
import com.yuncheng.oaApi.service.*;
import com.yuncheng.spcyApi.utils.DateConvert;
import com.yuncheng.oaApi.utils.GetUuIdUtils;
import com.yuncheng.utils.ThreadContextHelper;
import com.yuncheng.vo.*;
import groovy.lang.Lazy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import utils.LogUtils;
import utils.ObjectToMapUtils;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Api(tags = "NEW_NK-出差申批流程")
@RestController
@RequestMapping("/api/spzx-oa/nk-ccsp")
public class NewNkRsCcSpFlowController {
    private static final Logger log = LoggerFactory.getLogger(NewNkRsCcSpFlowController.class);

    @Resource
    private IOaSpcySqsxJobService spcySqsxJobService;

    @Resource
    private IOaYcSysUserService ycSysUserService;

    @Resource
    @Lazy
    private IOaSysTzMessageService sysTzMessageService;

    @Resource
    @Lazy
    private MyLcFlowService myLcFlowService;

    @Resource
    @Lazy
    private ISpcyLogService spcyLogService;

    @Resource
    @Lazy
    private IOaProcessBusinessService oaProcessBusinessService;

    @Resource
    @Lazy
    private NkRsCcSpFlowMapper nkRsCcSpFlowMapper;

    @Resource
    @Lazy
    private NewNkRsCcSpFlowService newNkRsCcSpFlowService;

    @Resource
    @Lazy
    private INkRsCcspService nkRsCcspService;





    /**
     * 流程列表分页查询
     * @param
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程监控-分页查询")
    @ApiOperation(value = "流程监控-分页查询")
    @GetMapping("flowJkPage")
    public HttpResult flowJkPage(
            NkRsCcSpVo nkRsCcSpVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        nkRsCcSpVo.setFlcmc(OaFlowConstant.NK_CCSP_NAME);
        Page<NkRsCcSpVo> page = new Page<>(pageNo, pageSize);

        IPage<NkRsCcSpVo> list = null;
        if (StringUtils.isNotBlank(nkRsCcSpVo.getOaid())){
            NkRsCcsp xzswsp = nkRsCcspService.getById(nkRsCcSpVo.getOaid());
            if (xzswsp != null){
                list = nkRsCcSpFlowMapper.flowJkPage(page,onlyCurrentUser,user,nkRsCcSpVo);
            }
        }



        return HttpResult.ok(list);
    }

    /**
     * 流程列表分页查询
     * @param
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程列表-分页查询")
    @ApiOperation(value = "流程列表-分页查询")
    @GetMapping("flowJobPage")
    public HttpResult<?> flowJobPage(
            NkRsCcSpVo nkRsCcSpVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        nkRsCcSpVo.setFlcmc(OaFlowConstant.NK_CCSP_NAME);
        if (StringUtils.isBlank(nkRsCcSpVo.getFblzt())) {
            nkRsCcSpVo.setFblzt(OaCommonFlowConstant.BLZT_DB);
        }
        Page<NkRsCcSpVo> page = new Page<>(pageNo, pageSize);
        IPage<NkRsCcSpVo> list = nkRsCcSpFlowMapper.flowJobPage(page, onlyCurrentUser, user, nkRsCcSpVo);
        return HttpResult.ok(list);
    }


    /**
     * 我的已办
     */
    @AutoLog(value = "流程列表-我的已办")
    @ApiOperation(value = "流程列表-我的已办")
    @GetMapping("myJobPage")
    public HttpResult<?> myJobPage(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            NkRsCcSpVo nkRsCcSpVo) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        Page<NkRsCcSpVo> page = new Page<>(pageNo, pageSize);
        IPage<NkRsCcSpVo> list = nkRsCcSpFlowMapper.myYbFlowPage(page, true, user, nkRsCcSpVo);
        return HttpResult.ok(list);
    }


    /**
     * 数据修订
     */
    @AutoLog(value = "列表-数据修订")
    @ApiOperation(value = "列表-数据修订")
    @GetMapping("Pagesjxd")
    public HttpResult<?> Pagesjxd(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            NkRsCcSpVo nkRsCcSpVo) {

        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }

        Page<NkRsCcSpVo> page = new Page<>(pageNo, pageSize);
        IPage<NkRsCcSpVo> list = nkRsCcSpFlowMapper.myYbFlowPage(page, false, user, nkRsCcSpVo);
        return HttpResult.ok(list);
    }






    @AutoLog(value = "发起出差审批流程")
    @ApiOperation(value = "发起出差审批流程")
    @PostMapping(value = "initBzFlow")
    public HttpResult<?> initBzFlow(@RequestBody NkRsCcsp nkRsCcsp) {

        String oaid = "";
        //当前人的id
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        if (currentUser == null) {
            return HttpResult.error("当前登录已失效，请重新登录");
        }
        if (StringUtils.isNotBlank(nkRsCcsp.getId())){
            NkRsCcsp nkids = nkRsCcspService.getById(nkRsCcsp.getId());

            ConvertUtils.register(new DateConvert(), Date.class);
            try {
                BeanUtils.populate(nkids, BeanUtils.describe(nkRsCcsp));
            } catch (IllegalAccessException e) {
                log.error("出错-保存事项【非法访问异常】,{}", e.getMessage());
            } catch (InvocationTargetException e) {
                log.error("出错-保存事项【调用TargetException】,{}", e.getMessage());
            } catch (NoSuchMethodException e) {
                log.error("出错-找不到可用方法", e.getMessage());
            }
            oaid = nkRsCcsp.getId();

            // Date日期单独做处理

            nkids.setFuserid(currentUser.getId());

            nkRsCcspService.updateById(nkids);
        }else {
            oaid = GetUuIdUtils.ReplaceUuId();
            String timeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

            nkRsCcsp.setId(oaid);

            nkRsCcsp.setFxm(currentUser.getName());
            nkRsCcsp.setFuserid(currentUser.getId());

            if (StringUtils.isBlank(nkRsCcsp.getFtbdw())){
                nkRsCcsp.setFtbdw(currentUser.getDeptName());
            }else {
                nkRsCcsp.setFtbdw(nkRsCcsp.getFtbdw());
            }
            nkRsCcsp.setFtbsj(timeStr);
            nkRsCcsp.setFlczt(OaCommonFlowConstant.FLOW_LCZB);

            nkRsCcspService.save(nkRsCcsp);
        }

        /**
         * @Author: lhb
         * @Description : 是否发起流程   如果是开始申请就跳转流程
         *               在这里设置  指定下个环节节点 做当前跳转流程的判断，然后设置变量接收环节的值，写到nextNodeName中
         * @DateTime:
         * @Params: Fsffqlc
         */
        String msg = "保存成功";
        String lcmbCode = OaFlowConstant.NK_CCSP;

        OaJobEntity job = new OaJobEntity();
        // 初始化流程
        Result result = newNkRsCcSpFlowService.createProcess(lcmbCode,oaid, currentUser);
        //做一次规则校验 如果查到此oaid 在表中已经插入 那就执行更新
        NkRsCcsp nkRsCcsp1 = nkRsCcspService.getById(oaid);
        List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        String bt = currentUser.getName()+"提交的出差申请"; //标题
        String zy = "申请日期:["+ nkRsCcsp1.getFtbsj() +"]"+"\n"
                +"出差开始时间:["+ nkRsCcsp1.getFccksrq() + "  "+nkRsCcsp1.getFcckssj() + "]"+"\n"
                +"出差结束时间:["+ nkRsCcsp1.getFccjsrq() +"  "+ nkRsCcsp1.getFccjssj() + "]"+"\n"
                +"出差地点:["+ nkRsCcsp1.getFccdd() + "]"+"\n"
                +"出差事由:["+ nkRsCcsp1.getFccsy() + "]"+"\n";
        if (oaProcessBusinessList.size() == 0){
            //初始化的时候 像 流程业务主表添加拼接初始化数据
            oaProcessBusinessService.addProcess(oaid,zy,bt,lcmbCode,OaFlowConstant.OA);

        }else {
            String id = oaProcessBusinessList.get(0).getId();  //当前已经插入的主键id 然后更新 摘要信息
            OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
            oaProcessBusiness.setFzy(zy);
            oaProcessBusinessService.updateById(oaProcessBusiness);

        }

        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }else {
            job = (OaJobEntity)result.getResult();
            if (job != null) {
                // 是否提交流程
                if(StringUtils.isBlank(oaid)){
                    return HttpResult.error("参数丢失");
                }
                String nextNodeId = "";
                String nextNodeDbrId = "";
                if (StringUtils.isNotBlank(nkRsCcsp.getFsffqlc()) && nkRsCcsp.getFsffqlc().equals(OaCommonFlowConstant.SFFQLC_YES)) {
                    //使用流程编码查询流程模板
//                    List<SysFlowTemple> templeList = sysFlowTempleService.list(new LambdaQueryWrapper<SysFlowTemple>().eq(SysFlowTemple::getFlcbm, lcmbCode));
//                    String templeId = templeList.get(0).getId();
//
//                    List<SysFlowNode> bgsshNodeList = sysFlowNodeService.list(new LambdaQueryWrapper<SysFlowNode>().eq(SysFlowNode::getFlcmbid, templeId)
//                            .eq(SysFlowNode::getFjdmc, OaFlowConstant.CCSP_HJMC_BGSSH));
//
//                    List<SysFlowNode>zxldNodeList = sysFlowNodeService.list(new LambdaQueryWrapper<SysFlowNode>().eq(SysFlowNode::getFlcmbid, templeId)
//                            .eq(SysFlowNode::getFjdmc, OaFlowConstant.CCSP_HJMC_ZXLDSH));
//
//                    String bgsshnodeId = bgsshNodeList.get(0).getId(); //办公室审核节点id
//                    String zxldnodeId = zxldNodeList.get(0).getId(); //中心领导审核节点id

//                    YcSysUser ycSysUser = ycSysUserService.getById(currentUser.getId());
                    //先判断是否为中心副主任 。在继续判断 是否是科室负责人
//                    if (ycSysUser.getOrgName().contains(CommonFlowConstant.ORG_NAME_ZXFZR)) {
//                        //如果填报部门为中心副主任 则跳到 中心领导审核
//                        nextNodeId = zxldnodeId;
//                        nextNodeDbrId = "";
//                    } else if (flowNodeDbrService.brksfzr()) {
//                        nextNodeId = bgsshnodeId;
//                        nextNodeDbrId = "";
//                    } else {
//                        nextNodeId = "";
//                        nextNodeDbrId = "";
//                    }

                    if (StringUtils.isBlank(nkRsCcsp.getFlczt())) {
                        nkRsCcsp.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
                    }
                    Result result1 = newNkRsCcSpFlowService.passJob(oaid,job.getId(),"同意", nextNodeId, nextNodeDbrId);
                    if (!result1.isSuccess()) {
                        return HttpResult.error(result.getMessage());
                    }
                    msg = "提交成功";
                    //提交完成后 更新通知信息
                    sysTzMessageService.tjMessage(oaid);

                    List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                            .eq(OaProcessBusiness::getFpid, oaid));
                    OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
                    OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
                    byId1.setFsfkch(0);
                    OaJobEntity oaJobEntity = spcySqsxJobService.getById(job);
                    if (oaJobEntity.getFhjmc().equals(OaFlowConstant.CCSP_HJMC_ZXLDSH)) {
                        byId1.setFsfkbx(OaFlowConstant.QXJ_YES);
                    }

                    byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
                    oaProcessBusinessService.updateById(byId1);

                    myLcFlowService.recall(oaid);
                }
            }
        }

        HashMap map = new HashMap();
        map.put("msg",msg);
        map.put("nkMap",nkRsCcsp);
        map.put("jobMap",job);

        return HttpResult.ok(map);
    }

    /**
     * 内控-出差审批保存接口
     */
    @AutoLog(value = "内控-出差审批保存接口")
    @ApiOperation(value = "内控-出差审批保存接口")
    @PostMapping(value = "/saveFlow")
    public HttpResult<?> saveFlow(@RequestBody OaFlowVo oaFlowVo) {
        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SAVE; // 保存

        String jobId = oaFlowVo.getJobid(); // 当前流程任务id
        String oaid = oaFlowVo.getOaid(); // 当前办公主键id
        String opinion = oaFlowVo.getOpinion(); // 办理意见

        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.NK_CCSP);
        }
        if (StringUtils.isBlank(jobId)){
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        // 流程处理
        Result httpResult = newNkRsCcSpFlowService.handleFlow(oaFlowVo, null, jobId, oaid, submitType, opinion);
        if (!httpResult.isSuccess()){
            return HttpResult.error(httpResult.getMessage());
        }
        Map map = new HashMap();
        HttpResult<Object> res = new HttpResult<>(true);
        res.setMessage("保存成功");
        res.setResult(map);
        return res;
    }


    @AutoLog(value = "内控-出差审批提交接口")
    @ApiOperation(value = "内控-出差审批提交接口")
    @PostMapping(value = "/submitFlow")
    public HttpResult<?> submitFlow(@RequestBody OaFlowVo oaFlowVo) {

        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SUBMIT; // 提交
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        String jobId = oaFlowVo.getJobid();




        String oaid = oaFlowVo.getOaid();
        String opinion = oaFlowVo.getOpinion();
        NkRsCcsp oaId = nkRsCcspService.getById(oaid);
        OaJobEntity job = spcySqsxJobService.getById(jobId);

        if (job.getFdbrid() != null && !job.getFdbrid().isEmpty()) {
            // 检查id是否在逗号分隔的字符串中
            boolean contains = job.getFdbrid().contains(currentUser.getId());
            if (!contains){
                throw new BusinessException("您没有权限提交该流程");
            }
        }



        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.NK_CCSP);
        }

        if (job.getFhjmc().equals(OaFlowConstant.CCSP_HJMC_CCSQ)){
            //重新获取摘要信息
            NkRsCcsp nkRsCcsp1 = nkRsCcspService.getById(oaid);
            List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                    .eq(OaProcessBusiness::getFpid, oaid));
            String bt = currentUser.getName()+"提交的出差申请"; //标题
            String zy = "申请日期:["+ nkRsCcsp1.getFtbsj() +"]"+"\n"
                    +"出差开始时间:["+ nkRsCcsp1.getFccksrq() + "  "+nkRsCcsp1.getFcckssj() + "]"+"\n"
                    +"出差结束时间:["+ nkRsCcsp1.getFccjsrq() +"  "+ nkRsCcsp1.getFccjssj() + "]"+"\n"
                    +"出差地点:["+ nkRsCcsp1.getFccdd() + "]"+"\n"
                    +"出差事由:["+ nkRsCcsp1.getFccsy() + "]"+"\n";
            if (oaProcessBusinessList.size() == 0){
                //初始化的时候 像 流程业务主表添加拼接初始化数据
                oaProcessBusinessService.addProcess(oaid,zy,bt,"NK_CCSP",OaFlowConstant.OA);

            }else {
                String id = oaProcessBusinessList.get(0).getId();  //当前已经插入的主键id 然后更新 摘要信息
                OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
                oaProcessBusiness.setFzy(zy);
                oaProcessBusinessService.updateById(oaProcessBusiness);

            }

        }else if (job.getFhjmc().equals(OaFlowConstant.CCSP_HJMC_ZXLDSH)) {

        } else {
            oaId.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        }
        if (StringUtils.isBlank(oaId.getFsffqlc())) {
            oaId.setFsffqlc(OaCommonFlowConstant.SFFQLC_YES);
        }

        nkRsCcspService.updateById(oaId);

        if (StringUtils.isBlank(jobId)) {
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        /* if (StringUtils.isBlank(opinion)){
            return HttpResult.error("请填写办理意见");2
        }*/

        OaJobEntity nowJob = null;
        Result httpResult1 = newNkRsCcSpFlowService.handleFlow(oaFlowVo, nowJob, jobId, oaid, submitType, opinion);
        if (!httpResult1.isSuccess()){
            return HttpResult.error(httpResult1.getMessage());
        }
        List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
        OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
        byId1.setFsfkch(0);

        if (job.getFhjmc().equals(OaFlowConstant.CCSP_HJMC_ZXLDSH)) {
            byId1.setFsfkbx(OaFlowConstant.QXJ_YES);
        }

        byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
        oaProcessBusinessService.updateById(byId1);

        //提交完成后 更新待办信息
        sysTzMessageService.tjMessage(oaid);
        myLcFlowService.recall(oaid);


        return HttpResult.ok("提交成功");
    }





    /**
     * 批量查询
     */
    @AutoLog(value = "批量查询")
    @ApiOperation(value = "批量查询")
    @ApiImplicitParam(value = "jobids", name = "jobids", required = true)
    @GetMapping(value = "queryBatchJobByJobIds")
    public HttpResult<?> queryBatchJobByJobIds(@RequestParam("jobids")String jobids) {
        if (StringUtils.isBlank(jobids)) {
            return HttpResult.error("参数不能为空,请选择数据");
        }
        List<Map> mapList = new ArrayList<>();
        List<String> jobidsList = Arrays.asList(jobids.split(","));
        if (CollectionUtils.isNotEmpty(jobidsList)) {
            for (String jobid : jobidsList){
                mapList.add(newNkRsCcSpFlowService.getJobConcernByJobId(jobid));
            }
        }
        return HttpResult.ok(mapList);
    }

    /**
     * 查询当前流程任务详情-通过当前流程任务id
     */
    @AutoLog(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiOperation(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiImplicitParam(value = "jobid", name = "流程任务id", required = true)
    @GetMapping(value = "queryJobByJobId")
    public HttpResult<?> queryJobByJobId(@RequestParam("jobid") String jobid) {
        if (StringUtils.isBlank(jobid)) {
            return HttpResult.error("流程任务id不能为空");
        }
        Map map = newNkRsCcSpFlowService.getJobConcernByJobId(jobid);
        return HttpResult.ok(map);
    }

    /**
     * 获取已办列表-通过当前流程id-自定义退回
     *
     * @param jobid
     * @return
     */
    @AutoLog(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiOperation(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobid", value = "流程任务id"),
            @ApiImplicitParam(name = "isZdhj", value = "是否指定环节，默认：true，指定")
    })
    @GetMapping(value = "queryAllYbJob")
    public HttpResult<?> queryAllYbJob(@RequestParam(value = "jobid", defaultValue = "") String jobid,
                                       @RequestParam(value = "isZdhj", defaultValue = "true") boolean isZdhj) {
        List<Map<String, String>> currentJobPrevious = newNkRsCcSpFlowService.getCurrentJobPrevious(jobid, isZdhj);
        return HttpResult.ok(currentJobPrevious);
    }

    /**
     * 退回环节
     *
     * @return
     */
    @AutoLog(value = "自定义-退回环节")
    @ApiOperation(value = "自定义-退回环节")
    @PostMapping(value = "returnUpperzdyFlowJob")
    public HttpResult<?> returnUpperzdyFlowJob(@RequestBody OaReturnVo oaReturnVo) {
        newNkRsCcSpFlowService.returnZdJob(oaReturnVo);

        //退回更新通知信息
        OaJobEntity oaJobEntity = spcySqsxJobService.getById(oaReturnVo.getJobid());
        String fpid = oaJobEntity.getFpid();
        sysTzMessageService.endMessage(fpid,false,false,true);

        return HttpResult.ok("退回成功");
    }

    @AutoLog(value = "删除出差申请")
    @ApiOperation(value = "删除出差申请")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobids",value = "流程任务id,逗号分割",required = true)
    })
    @DeleteMapping(value = "deleteLgqsFlowJob")
    public HttpResult<?> deleteLgqsFlowJob(@RequestParam(value = "jobids") String jobids){
        if (StringUtils.isBlank(jobids)){
            return HttpResult.error("参数不能为空");
        }
        List<String> jobIdList = Arrays.asList(jobids.split(","));
        String logNr = "";
        Map<String, Object> map = new HashMap<>();
        if (CollectionUtils.isNotEmpty(jobIdList)){
            List<OaJobEntity> jobList = spcySqsxJobService.listByIds(jobIdList);
            if (CollectionUtils.isNotEmpty(jobList)){
                for (OaJobEntity job : jobList) {
                    spcySqsxJobService.removeById(job.getId());
                    NkRsCcsp nkRsYstpsq = nkRsCcspService.getById(job.getFpid());
                    if (nkRsYstpsq != null) {
                        nkRsCcspService.removeById(job.getFpid());

                        logNr = "删除出差申请" + job.getFhjmc() + ": ";
                        map = ObjectToMapUtils.objectToMap(nkRsYstpsq);
                        logNr += LogUtils.MapToStringMethod(map);

                        spcyLogService.addLogs(job.getFhjmc(), logNr, job.getFpid(), OaFlowConstant.NK_CCSP, OaCommonFlowConstant.LOGS_SYS_TYPE_SC);
                    }
                }
            }
        }

        return HttpResult.ok("删除成功");
    }


    /**
     * 获取本部门人员
     */
    @AutoLog(value = "获取本部门人员")
    @ApiOperation(value = "获取本部门人员")
    @GetMapping(value = "getBmUser")
    public HttpResult getBmUser(){
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        String deptId = currentUser.getDeptId();
        String deptName = currentUser.getDeptName();
        List<YcSysUser> ycSysUsers = ycSysUserService.list(new LambdaQueryWrapper<YcSysUser>()
                .eq(YcSysUser::getOrgId, deptId)
                .ne(YcSysUser::getId, currentUser.getId()));

        List list = new ArrayList<>();

        for (YcSysUser user:ycSysUsers ){
            Map userMap = new HashMap<>();
            userMap.put("userId",user.getId());
            userMap.put("userName",user.getRealname());
            userMap.put("bmmc",deptName);
            list.add(userMap);
        }
        return HttpResult.ok(list);
    }



    /**
     * 修订获取本部门人员
     */
    @AutoLog(value = "修订获取本部门人员")
    @ApiOperation(value = "修订获取本部门人员")
    @GetMapping(value = "getBmUserxd")
    public HttpResult getBmUserxd(String oaid){
        NkRsCcsp ccsp = nkRsCcspService.getById(oaid);
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        String deptId = currentUser.getDeptId();
        String deptName = currentUser.getDeptName();
        List<YcSysUser> ycSysUsers = ycSysUserService.list(new LambdaQueryWrapper<YcSysUser>()
                .eq(YcSysUser::getOrgId, deptId)
                .ne(YcSysUser::getId, ccsp.getFuserid()));

        List list = new ArrayList<>();

        for (YcSysUser user:ycSysUsers ){
            Map userMap = new HashMap<>();
            userMap.put("userId",user.getId());
            userMap.put("userName",user.getRealname());
            userMap.put("bmmc",deptName);
            list.add(userMap);
        }
        return HttpResult.ok(list);
    }




}
